using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using DATA.ManagerObjects;
using DATA.BusinessObjects;
using DATA.Base;

namespace DATA.UnitTests
{
	[TestFixture]
    public partial class MatdosudungphongTests : UnitTestbase
    {
        [SetUp]
        public void SetUp()
        {
            manager = managerFactory.GetMatdosudungphongManager();
            manager.Session.BeginTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            manager.Session.RollbackTransaction();
            manager.Dispose();
        }
        
        protected DATA.ManagerObjects.IMatdosudungphongManager manager;
		
		protected DATA.BusinessObjects.Matdosudungphong CreateNewMatdosudungphong()
		{
			DATA.BusinessObjects.Matdosudungphong entity = new DATA.BusinessObjects.Matdosudungphong();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = "Test ";
			
			entity.Thang = 85;
			
			return entity;
		}
		protected DATA.BusinessObjects.Matdosudungphong GetFirstMatdosudungphong()
        {
            IList<DATA.BusinessObjects.Matdosudungphong> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				DATA.BusinessObjects.Matdosudungphong entity = CreateNewMatdosudungphong();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                DATA.BusinessObjects.Matdosudungphong entityA = CreateNewMatdosudungphong();
				manager.Save(entityA);

                DATA.BusinessObjects.Matdosudungphong entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                DATA.BusinessObjects.Matdosudungphong entityA = GetFirstMatdosudungphong();
				
				entityA.Thang = 20;
				
				manager.Update(entityA);

                DATA.BusinessObjects.Matdosudungphong entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Thang, entityB.Thang);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                DATA.BusinessObjects.Matdosudungphong entity = GetFirstMatdosudungphong();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

